<template>
  <div>
    <el-upload
      ref="upload"
      :action="''"
      :show-file-list='false'
      :before-upload="handleBefore"
      :http-request="resquest"
    >
      <el-button slot="trigger" icon="el-icon-upload2">导入文件</el-button>
      <!-- <div slot="tip" class="el-upload__tip">{{tips}}</div> -->
    </el-upload>
  </div>
</template>

<script>
export default {
  name: "PressureTestIndex",

  data() {
    return {
        file:null,
        type:['.xls','.xlsx']
    };
  },
 props:{
  tips:{
      type:String,
      default:'只能上传xls/xlsx文件'
  }
 },
  mounted() {},

  methods: {
    handleBefore(file){
        const {name} = file
        const inedex = name.lastIndexOf('.')
        const suffix = name.slice(inedex)
        console.log('suffix',suffix)
        if(!this.type.includes(suffix)){
          this.$message.warning('请选择EXCEL文件')
          return false
        }
       this.file = file
       return true
    },
    resquest() {
      this.$emit("http-request",this.file);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>